<template>
    <keep-alive v-if="isKeepAlive">
        <router-view></router-view>
    </keep-alive>
    <router-view v-else></router-view>
</template>

<script>
    export default {
        name: "StElRouterView",
        // 路由层级 在多级路由下时可能中间级不会缓存问题 从1开始
        props: {
            level: Number
        },
        computed: {
            isKeepAlive(){
                let r = false
                if(this.level != null && this.level != undefined){
                    if(this.$route.matched.length > this.level - 1){
                        let matched = this.$route.matched[this.level - 1]
                        r = matched.meta.keepAlive === true
                    }
                }else {
                    r = this.$route.meta.keepAlive === true
                }
                return r
            }
        },
        data() {
            return {
            }
        },
        methods: {

        },
        watch:{
        }
    }
</script>

<style scoped>

</style>